package com.exercise.AndroidCamera;

import java.util.ArrayList;

import com.exercise.AndroidCamera.CreateGroupActivity.createGroupAsync;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.webkit.WebView.FindListener;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.HorizontalScrollView;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;

public class FriendListAdapter2 extends BaseAdapter{
   
   private Context context;
   private int friendCount, layoutId;
   private ArrayList<String> friendList;
   private LayoutInflater inflater;
   CheckBox check;
   
   public FriendListAdapter2(Context context, int layoutId, ArrayList<String> friendList, int friendCount) {
      // TODO Auto-generated constructor stub
      this.context = context;
      this.layoutId = layoutId;
      this.friendList = friendList;
      this.friendCount = friendCount;
      inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
   }
   @Override
   public int getCount() {
      // TODO Auto-generated method stub
      return friendList.size();
   }

   @Override
   public Object getItem(int position) {
      // TODO Auto-generated method stub
      return null;
   }
   
   @Override
   public long getItemId(int position) {
      // TODO Auto-generated method stub
      return 0;
   }
   
   private class ViewHolder 
   {
      TextView apkName;
      CheckBox ck1;
   }
   
   @Override
   public View getView(final int position, View convertView, ViewGroup parent) {
      final ViewHolder holder;
      
      // TODO Auto-generated method stub
      if(convertView == null) {
         convertView = inflater.inflate(layoutId, parent, false);
         
      }
      
      CheckBox friends = new CheckBox(context);
      friends.setText(friendList.get(position));
      friends.setId(position);
      Log.d("position", position+"");
      
	final CreateGroupActivity a = (CreateGroupActivity)context;

      
      friends.setOnCheckedChangeListener(new OnCheckedChangeListener(){
            @Override
            public void onCheckedChanged(CompoundButton buttonView,
                  boolean isChecked) {
               // TODO Auto-generated method stub
            	
               if(isChecked == true){
            	  a.itemChecked[position] = true;
               }
               else
               {
             	  a.itemChecked[position] = false;

               }
            }
         });
      

         return friends;
   }
}